//
//  NoteCell.m
//  PlayView
//
//  Created by houshijia on 16/10/9.
//  Copyright © 2016年 houshijia. All rights reserved.
//

#import "NoteCell.h"
#import "dangXiaoHeader_note.h"
@implementation NoteCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

+(instancetype)noteCellWithTableView:(UITableView*)tableView{
    static NSString *ident = @"note";
    NoteCell *cell = [tableView dequeueReusableCellWithIdentifier:ident];
    if (!cell) {
        cell = [[NoteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ident];
        
    }
    return cell;
}
-(void)setupUI{
    [self.contentView addSubview:self.unameLbl];
    [self.contentView addSubview:self.timeLbl];
    [self.contentView addSubview:self.numLbl];
    [self.contentView addSubview:self.nrLbl];
     self.zanBtn = [[ZanButton alloc]initWithFrame:CGRectMake(SIZEWIDTH-50, 16, 50, 20)];
    [self.contentView addSubview:self.zanBtn];

}
-(void)setModel:(NoteModel *)model{
    _model = model;
    //名字
    self.unameLbl.text = _model.name;
    self.unameLbl.font = NormalFont(24);
    self.unameLbl.frame = CGRectMake(15, 20, 0, 0);
    self.unameLbl.numberOfLines = 1;
    self.unameLbl.lineSpace = 0;
    [self.unameLbl sizeToFit];
    self.unameLbl.textColor = Color_title_black_64;
    
    //时间
    self.timeLbl.text = [NSString timeFromTimestamp:_model.input_time];
    self.timeLbl.font = NormalFont(24);
    self.timeLbl.frame = CGRectMake(CGRectGetMaxX(self.unameLbl.frame)+15, 20, 0, 0);
    self.timeLbl.numberOfLines = 1;
    self.timeLbl.lineSpace = 0;
    [self.timeLbl sizeToFit];
    self.timeLbl.textColor = Color_title_black_64;
    
   
    self.zanBtn.title_text.text = _model.zanCount;
    if([_model.isdz integerValue]==0){
        self.zanBtn.selected = NO;
        
    }else{
        self.zanBtn.selected = YES;

    }
    
    //内容
    //    self.nrLbl.backgroundColor = [UIColor yellowColor];
    self.nrLbl.text = _model.bjnr;
    self.nrLbl.numberOfLines = 0;
    self.nrLbl.font = NormalFont(28);
    CGRect rect = [self.nrLbl getLableHeightWithMaxWidth:SIZEWIDTH-30];
    CGFloat height1 = rect.size.height;
    
    if (height1>28 && height1<30) {
        
        self.nrLbl.lineSpace = 0;
        
    }else{
        
        self.nrLbl.lineSpace = 8;
        height1 = [self.nrLbl getLableHeightWithMaxWidth:SIZEWIDTH-30].size.height;
        
        
    }

    self.nrLbl.frame = CGRectMake(15, CGRectGetMaxY(self.unameLbl.frame)+15, SIZEWIDTH-30, height1);
    self.nrLbl.textColor = Color_title_black_87;

}

#pragma mark- 解决最后一个cell不显示分割线
- (void)layoutSubviews {
    [super layoutSubviews];
    for (UIView *subview in self.contentView.superview.subviews) {
        if ([NSStringFromClass(subview.class) hasSuffix:@"SeparatorView"]) {
            subview.hidden = NO;
            CGRect frame = subview.frame;
            frame.origin.x += 0;
            frame.size.width -= 0;
            subview.frame =frame;
        }
    }
}


#pragma mark- 懒加载
-(UILabel *)unameLbl{
    if (!_unameLbl) {
        _unameLbl = [UILabel new];
    }
    return _unameLbl;
}
-(UILabel *)timeLbl{
    if (!_timeLbl) {
        _timeLbl = [UILabel new];
    }
    return _timeLbl;
}
-(UILabel *)numLbl{
    if (!_numLbl) {
        _numLbl = [UILabel new];
    }
    return _numLbl;
}
-(UILabel *)nrLbl{
    if (!_nrLbl) {
        _nrLbl = [UILabel new];
    }
    return _nrLbl;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
